<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>测试工具类</title>
</head>
<body>

    <div id="clock"></div>
    <div id="clock2"></div>
    <div id="countDown"></div>

    <script src="./utils_time.js"></script>
    <script src="./utils_array.js"></script>
    <script>
        //获取格式化后的日期时间
        var dateFormat = dateUtils.getDateFormat("YYYY-mm-dd", new Date());
        var dateFormat2 = dateUtils.getDateFormat("YYYY-mm-dd HH:MM", new Date());
        var dateFormat3 = dateUtils.getDateFormat("YYYY-mm-dd HH:MM:SS", new Date());
        //时间戳形式
        var dateFormat4 = dateUtils.getDateFormat("YYYY-mm-dd HH:MM:SS", new Date().getTime(), true);
        console.log(dateFormat, dateFormat2, dateFormat3, dateFormat4);

        //时钟效果
        dateUtils.getClock(document.getElementById('clock'));
        //自定义时钟效果
        setInterval(function () {
            var time = dateUtils.getDateString(new Date(), true);
            var fmt = `${time.y}.${time.m}.${time.d} 现在是 ${time.h}:${time.M}:${time.s} 今天是 ${time.week}`
            document.getElementById("clock2").innerHTML = fmt;
        }, 1000);

        //倒计时
        var starTime = "2021-3-1 15:20:20"; //开始时间
        var endTime = "2021-3-3 15:20:20";  //结束时间
        //启动倒计时
        dateUtils.countDown(new Date(starTime), new Date(endTime), function(d,h,m,s){
            document.getElementById("countDown").innerHTML = `活动日期：${starTime} 至 ${endTime}，还有${d}天，${h}小时，${m}分，${s}秒`;
        });

        //检测是否是数组、对象形式的类数组
        var a=[1,2,3,4,5,6,3,7,8,3];    //数组
        var b={};b[0]='tom';b.length=1; //对象转换为数组，类数组
        var c={};   //对象
        console.log(typeUtils.isArray(a),typeUtils.isArray(b),typeUtils.isArray(c));

        //对象转字符串
        var o1={"0":"aa","1":"bb","2":"cc",length:3};
        var tostring1 = typeUtils.objectToString(o1);
        var tostring2 = typeUtils.objectToString(o1, '-');
        console.log(tostring1, tostring2);

        //对象转数组
        var array1 = typeUtils.objectToArray(o1);
        console.log(array1);

        //对象转数组，且每个属性值转为大写字母
        var array2 = typeUtils.objectToUpperCase(o1);
        console.log(array2);

        //对象转数组，且每个属性值转为大写字母
        var string1 = "apple 100 apple 200";
        var string2 = typeUtils.stringSymbol(string1, '+');
        console.log(string2);

        //字符串截取
        var string3 = typeUtils.stringFilter(string1, /\d/);    //截取数字部分
        console.log(string3);

        //数组每个元素转为字符串
        var arr1 = [1, 2, 3, 4, 5, 6, 7, 8, 9];
        var array3 = typeUtils.toStringArray(arr1);
        console.log(array3);
        
        //数组每个元素转为首字母大写
        var arr2 = ['apple', 'banana','orange'];
        var array4 = typeUtils.toTitleCase(arr2);
        console.log(array4);

        //数组每个元素转为首字母大写
        var arr3 = ['100.55', '200.52','300.15'];
        var array5 = typeUtils.toNumberArray(arr3);
        console.log(array5);

        //数组求和、阶乘、求和且四舍五入
        var array6 = typeUtils.arrayToNumber(arr3);
        var array7 = typeUtils.arrayToNumber(arr3, 'sum');
        var array8 = typeUtils.arrayToNumber(arr3, 'fact');
        console.log(array6, array7, array8);

        //数组求和、阶乘、求和且四舍五入
        var arr4 = [10,5,6,2,1];
        var array9 = typeUtils.arrayToOddEven(arr4);    //保留偶数
        var array10 = typeUtils.arrayToOddEven(arr4, true); //保留奇数
        console.log(array9, array10);

        //删除为空的数组元素
        var arr5 = [10,'5','','  ',200];
        var array11 = typeUtils.arrayFilterEmpty(arr5);    //保留偶数
        console.log(array11);

        //数组去重
        var arr6 = [10,'10',10,200,300,'aaa',200,'bbb','aaa'];
        var array12 = typeUtils.arrayRemoveDuplication(arr6);    //保留偶数
        console.log(array12);

        //数组排序
        var arr7 = [10, 20, 1, 2];
        var array13 = typeUtils.sort(arr7); //正序
        console.log(array13, arr7);
        var arr8 = [10, 20, 1, 2];
        var array14 = typeUtils.sort(arr8); //倒序
        console.log(array14, arr8);
        var arr9 = ['abc', 'BBC', 'ABC'];
        var array15 = typeUtils.sort(arr9, 3, true); //不区分大小写正序，不改变原数组
        console.log(array15, arr9);
    </script>
</body>
</html>